home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Expander Classes / CExpanderPane.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  6.1 KB  |  258 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.     CExpanderPane.h
  3.  
  4.     Copyright © 1994 B-Ray Software. All rights reserved.
  5.     Developed using Symantec C++ 7.0.2 and Symantec's TCL library.
  6.     Portions of this code courtesy Symantec, Inc.
  7.  
  8.     This code may be freely distributed as long as this notice remains. This code
  9.     may not be used in any commercial software without the consent of B-Ray Software.
  10.  
  11.     ---
  12.  
  13.     CExpanderPane brings together the CPane and CColumnizer classes and provides the
  14.     appropriate linkage to make them work together.
  15.  
  16. ***********************************************************************************/
  17. #include "CExpanderPane.h"
  18. #include "ExpanderMessages.h"
  19.  
  20. TCL_DEFINE_CLASS_D2( CExpanderPane, CPane, CColumnizer );
  21.  
  22.  
  23. /*
  24.  * CExpanderPane constructor
  25.  *
  26.  * Default constructor - should only be called when created by a file read.
  27.  */
  28.  
  29. CExpanderPane :: CExpanderPane() : CPane(), CColumnizer()
  30. {
  31.     selected = FALSE;
  32.     canSelect = FALSE;
  33.  
  34.     TCL_END_CONSTRUCTOR
  35. }
  36.  
  37.  
  38. /*
  39.  * CExpanderPane constructor
  40.  *
  41.  * Normal constructor - should always be called when creating a new
  42.  * CExpanderPane object in code.
  43.  */
  44.  
  45. CExpanderPane :: CExpanderPane( CView *anEnclosure, CBureaucrat *aSupervisor,
  46.                               short aWidth, short aHeight,
  47.                               short aHLoc, short aVLoc,
  48.                               SizingOption aHSizing, SizingOption aVSizing )
  49.                     : CPane( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
  50.                              aHSizing, aVSizing ), CColumnizer()
  51. {
  52.     UseLongCoordinates( TRUE );
  53.     selected = FALSE;
  54.     canSelect = FALSE;
  55.  
  56.     TCL_END_CONSTRUCTOR
  57. }
  58.  
  59.  
  60. /*
  61.  * CExpanderPane destructor
  62.  *
  63.  * Just a place-holder for Inspector.
  64.  */
  65.  
  66. CExpanderPane :: ~CExpanderPane()
  67. {
  68.     TCL_START_DESTRUCTOR
  69. }
  70.  
  71.  
  72. /*
  73.  * ChangeSelf method - OVERRIDE
  74.  *
  75.  * Resizes ourselves based on the sizes of our children.
  76.  */
  77.  
  78. void CExpanderPane :: ChangeSelf( long changedIndex, Rect *delta )
  79. {
  80.     short    aHeight, aWidth;
  81.  
  82.     GetFamilySize( &aWidth, &aHeight );        // get dimensions of rectangle that contain our children
  83.     SetExpanderSize( aWidth, aHeight );        // become that rectangle
  84. }
  85.  
  86.  
  87. /*
  88.  * SetExpanderSize method
  89.  *
  90.  * Utilizes ChangeSize method to change our size. Afterwards, tells parent
  91.  * that we have changed.
  92.  */
  93.  
  94. void CExpanderPane :: SetExpanderSize( short aWidth, short aHeight )
  95. {
  96.     Rect    delta = { 0, 0, 0, 0 };
  97.  
  98.     delta.right = aWidth - width;                // create change dimensions
  99.     delta.bottom = aHeight - height;
  100.     if ( delta.right || delta.bottom ) {
  101.         ChangeSize( &delta, TRUE );                    // change frame
  102.         TellParent( kRowColChildChanged, &delta );    // tell parent of our change
  103.     }
  104. }
  105.  
  106.  
  107. /*
  108.  * SetSelectedState method
  109.  *
  110.  * Begins process that selects a pane for hilighting. If the pane cannot be selected,
  111.  * or the state is FALSE, then no pane will be selected.
  112.  */
  113.  
  114. void CExpanderPane :: SetSelectedState( Boolean aFlag )
  115. {
  116.     TellParent( kExpanderChildSelect, ( aFlag && canSelect ) ? PaneToChild() : NULL );
  117. }
  118.  
  119.  
  120. /*
  121.  * DoClick method - OVERRIDE
  122.  *
  123.  * Handles a mouse click in the pane's area. If the mouse is let up in the
  124.  * pane, and the pane is selectable, then the pane will become selected.
  125.  */
  126.  
  127. void CExpanderPane :: DoClick( Point hitPt, short modifierKeys, long when )
  128. {
  129.     Boolean        wasInButton = TRUE;
  130.     Point        where;
  131.     Rect        btnFrame;
  132.  
  133.     if ( ! canSelect )                    // don't even bother if we can't be selected
  134.         return;
  135.  
  136.     Prepare();
  137.  
  138.     LongToQDRect( &frame, &btnFrame );    // get QD coordinates
  139.  
  140.     while ( StillDown() ) {                // watch mouse until button is up
  141.         GetMouse( &where );
  142.         wasInButton = PtInRect( where, &btnFrame );
  143.     };
  144.  
  145.     if ( wasInButton ) {
  146.         SetSelectedState( TRUE );        // change our state
  147.     }
  148. }
  149.  
  150.  
  151. /*
  152.  * ChildMessage method - OVERRIDE
  153.  *
  154.  * Handles kExpanderChildSelect messages. We don't handle the selection message
  155.  * in this class. Derived classes must. However, we do check to see if we are at
  156.  * the top of the family tree (parent == NULL), and if so, we echo the selection
  157.  * message back down the tree. This two-stage process is necessary to properly
  158.  * handle the selection of children within children.
  159.  */
  160.  
  161. void CExpanderPane :: ChildMessage( CFamily *aChild, long message, void *param )
  162. {
  163.     if ( message == kExpanderChildSelect ) {
  164.         if ( itsParent ) {                        // still can go up the tree
  165.             TellParent( message, param );
  166.         }
  167.         else {                                    // at root of tree - send message back to leaves
  168.             TellChildren( message, param );
  169.         }
  170.     }
  171.     else {
  172.         CColumnizer::ChildMessage( aChild, message, param );
  173.     }
  174. }
  175.  
  176.  
  177. /*
  178.  * ParentMessage method - OVERRIDE
  179.  *
  180.  * Handles kExpanderChildSelect messages. When we receive this message from 
  181.  * our parent, we check to see if the parameter is us. If so, we become selected.
  182.  * Otherwise, ignore it.
  183.  */
  184.  
  185. void CExpanderPane :: ParentMessage( long message, void *param )
  186. {
  187.     if ( message == kExpanderChildSelect ) {
  188.         Boolean        newSel = (CFamily *)param == PaneToChild();
  189.         if ( newSel != selected ) {            // may be on or off
  190.             selected = newSel;
  191.             BecomeGopher( newSel );            // become/relinquish gopher
  192.             Refresh();                        // regardless, redraw to add/remove hilighting
  193.         }
  194.     }
  195.  
  196.     CColumnizer::ParentMessage( message, param );
  197. }
  198.  
  199.  
  200. /*
  201.  * HiliteSelf method
  202.  *
  203.  * Utility method that properly hilites the frame of the pane. Should be called as the last
  204.  * thing to do in a pane's Draw() method.
  205.  */
  206.  
  207. void CExpanderPane :: HiliteSelf( Boolean state )
  208. {
  209.     if ( ! printing && IsSelected() ) {
  210.         LongRect    aFrame;
  211.         Rect        qdRect;
  212.  
  213.         Prepare();
  214.  
  215.         GetFrame( &aFrame );
  216.         FrameToQDR( &aFrame, &qdRect );
  217.  
  218.         TCLSetHiliteMode();
  219.         InvertRect( &qdRect );
  220.  
  221.         if ( ! state ) {
  222.             InsetRect( &qdRect, 1, 1 );
  223.             TCLSetHiliteMode();
  224.             InvertRect( &qdRect );
  225.         }
  226.     }
  227. }
  228.  
  229.  
  230. /*
  231.  * PutTo method - OVERRIDE
  232.  *
  233.  * Writes to the stream all of the info we need to save.
  234.  */
  235.  
  236. void CExpanderPane :: PutTo( CStream &stream )
  237. {
  238.     stream << selected << canSelect;
  239.  
  240.     CPane::PutTo( stream );                    // let our CPane parent access stream
  241.     CColumnizer::PutTo( stream );            // let our CColumnizer parent access stream
  242. }
  243.  
  244.  
  245. /*
  246.  * GetFrom method - OVERRIDE
  247.  *
  248.  * Reads from the stream all of the info that we saved.
  249.  */
  250.  
  251. void CExpanderPane :: GetFrom( CStream &stream )
  252. {
  253.     stream >> selected >> canSelect;
  254.  
  255.     CPane::GetFrom( stream );            // let our CPane parent access stream
  256.     CColumnizer::GetFrom( stream );        // let our CColumnizer parent access stream
  257. }
  258.